home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / Run & Stumpy / source / bootblock.cp < prev    next >
Encoding:
Text File  |  1992-06-19  |  855 b   |  46 lines  |  [TEXT/MPS ]

  1. #include <resources.h>
  2. #include <memory.h>
  3.  
  4. #include "inttypes.h"
  5. #include "rawdrive.h"
  6. #include "bootblock.h"
  7.  
  8. bootblock::bootblock()
  9.   {
  10.     uint32 position=0;
  11.     
  12.     Handle res= GetResource('Boot',128);
  13.     if ( res == 0 )
  14.         return;
  15.     insert( res, position );
  16.     
  17.     res= GetResource('Boot',129);
  18.     if ( res == 0 )
  19.         return;
  20.     insert( res, position );
  21.     
  22.     zero( position );
  23.   }
  24.  
  25. OSErr bootblock::install( const FSSpec& volume )
  26.   {
  27.     rawdrive drive(volume);
  28.     uint32 amount= sizeof(data);
  29.     return drive.write( 0, data, amount );
  30.   }
  31.  
  32. void bootblock::insert( Handle h, uint32& position )
  33.   {
  34.     uint32 oldposition= position;
  35.     position+= GetHandleSize(h);
  36.     if ( position > sizeof(data) )
  37.         position= sizeof(data);
  38.     BlockMove( *h, data+oldposition, position-oldposition );
  39.   }
  40.  
  41. void bootblock::zero( uint32 from )
  42.   {
  43.     for ( ; from < sizeof(data); from++ )
  44.         data[from]=0;
  45.   }
  46.